package com.sunshine.simplehospital.bean

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase

/**
 * Created by sunshine on 2020/4/28
 */

@Database(entities = [User::class, Register::class], version = 1, exportSchema = false)
abstract class SimpleHospitalDatabase : RoomDatabase(){
    abstract val simpleHospitalDao: SimpleHospitalDao?

    companion object {
        private var simpleHospitalDatabase: SimpleHospitalDatabase? = null
        @Synchronized
        fun getDatabase(context: Context): SimpleHospitalDatabase {
            if (simpleHospitalDatabase == null){
                simpleHospitalDatabase = Room.databaseBuilder(context.applicationContext, SimpleHospitalDatabase::class.java, "SimpleHospitalDatabase.db")
                    .allowMainThreadQueries()
                    .build()
            }
            return simpleHospitalDatabase!!
        }
    }
}